package com.example.studentmanage.dao;

import com.example.studentmanage.pojo.Course;
import com.example.studentmanage.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

@Repository
public class StudentDao {
    private static Map<Integer, Student> studentMap=null;

    @Autowired
    CourseDao courseDao;

    static {
        studentMap=new HashMap<Integer, Student>();
        studentMap.put(1001,new Student(1001,"张三","软件工程","计算机",new Course(1,"java","jack")));
        studentMap.put(1002,new Student(1002,"李四","软件","计算机",new Course(1,"C++","jack")));
        studentMap.put(1003,new Student(1003,"王五","工程","计算机",new Course(1,"python","lily")));
    }

    private static Integer initId = 1006;
    public void save(Student student){
        if(student.getId()==null){
                student.setId(initId++);
        }
        studentMap.put(student.getId(),student);
    }

    public Collection<Student> getAllStudent(){
        return studentMap.values();
    }

    public Student getStudentById(Integer id){
        return studentMap.get(id);
    }

    public void delete(Integer id){
        studentMap.remove(id);
    }

}
